$(".ml").click(e=>{
    if(e.target.nodeName=="DD"){
        $(e.target).addClass("cur").siblings().removeClass('cur');
    }else if(e.target.nodeName=="SPAN"){
        $(e.target).parent().addClass("cur").siblings().removeClass('cur');
    }
})

//获取操作对象
var pagin = document.querySelector('.pagination')

$.ajax({
    "url": "../php/list.php",
    "dataType": "JSON",
    "success": data => {
        console.log(data);
        //设置分页参数对象
        var o1 = {
            textInfo: {
                first: "首页",
                last: "尾页",
                prev: "上一页",
                next: "下一页",
            },
            pageInfo: {
                pagenum: 1,
                pagesize: 12,
                totalsize:data.length,
                totalpage:Math.ceil(data.length/12),
            }
        }
        //创建分页器实例化对象
        new Pagination(pagin, o1, (m) => {
            //根据页码获取当前页显示的数据
            var ar1=data.slice((m-1)*12,m*12)
            //创建拼接字符串
            var str = ``
            //遍历数组对象
            ar1.forEach(item=>{
                str+=`
                <li id=${item.id}>
                    <a>
                        <img src="${item.img}" alt="">
                        <div>
                            <p>${item.name}</p>
                            <p class="p1">￥ <span>${item.price}</span></p>
                        </div>
                    </a>
                </li>
                `
            })
            $(".ul_lists").html(str);
        })
    }
})

$(".kai").click(()=>{
    if($(".kai").html()=="展开"){
        $(".kai").html("收起")
        $("#zz").css("max-height","26px")
    }else{
        $(".kai").html("展开")
        $("#zz").css("max-height","120px")
    }
    
})

$(".ul_lists").click(e=>{
    console.log(e.target)
    if(e.target.nodeName=='SPAN'){
        sessionStorage.id=$(e.target).parent().parent().parent().parent().attr("id")
        console.log(sessionStorage.id)
    }else if(e.target.nodeName=='A'){
        sessionStorage.id=$(e.target).parent().attr("id")
        console.log(sessionStorage.id)
    }else if(e.target.nodeName=='P'){
        sessionStorage.id=$(e.target).parent().parent().parent().attr("id")
        console.log(sessionStorage.id)
    }else if(e.target.nodeName=='IMG'){
        sessionStorage.id=$(e.target).parent().parent().attr("id")
        console.log(sessionStorage.id)
    }
    location='xiangqing.html'
})